/*
 * @Author: chengjiang
 * @Date: 2024-06-08 16:43:15
 * @Description: 
 */
import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

import WindiCSS from 'vite-plugin-windicss'
// console.log(process)
// console.log(import.meta.env.VITE_APP_URL)

// https://vitejs.dev/config/
export default defineConfig({
  base: "./",
  plugins: [
    WindiCSS(),
    vue(),
    // ...
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
      '_c': fileURLToPath(new URL('./src/components', import.meta.url)),
    }
  },
  server: {
    port: 8080,
    proxy: {
      "/juhe_api": {
        //'/api'是自行设置的请求前缀
        target: "http://web.juhe.cn",
        changeOrigin: true, //用于控制请求头中的host值
        rewrite: (path) => path.replace(/^\/juhe_api/, ""), //路径重写，（正则）匹配以api开头的路径为空（将请求前缀删除）
      },
      "/djkx9999_api": {
        //'/api'是自行设置的请求前缀
        target: "https://djkx.djkx9999.com",
        // target: "http://119.91.131.41:8080",
        changeOrigin: true, //用于控制请求头中的host值
        rewrite: (path) => path.replace(/^\/djkx9999_api/, ""), //路径重写，（正则）匹配以api开头的路径为空（将请求前缀删除）
      },
      "/custgold_api": {
        target: "http://www.idjyj.com",
        changeOrigin: true, //用于控制请求头中的host值
        rewrite: (path) => path.replace(/^\/custgold_api/, ""), //路径重写，（正则）匹配以api开头的路径为空（将请求前缀删除）
      },
      '/back': {
        target: 'http://www.pggold.cn/back',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path.replace('/back/', '/')
      }
    }
  }
})
